package org.osprey.apidoc.converter;

import io.vertx.core.json.JsonObject;
import org.osprey.apidoc.pojo.User;

/**
 * @ClassName UserConverter
 * @Description: TODO
 * @Author Osprey
 * @Date 2019/10/21
 * @Version V2.0
 **/
public class UserConverter {

    public static void fromJson(JsonObject jsonObject, User user) {
        if (jsonObject.getValue("userID") instanceof Integer) {
            user.setUserID(jsonObject.getInteger("userID"));
        }
        if (jsonObject.getValue("userName") instanceof String) {
            user.setUserName(jsonObject.getString("userName"));
        }
        if (jsonObject.getValue("userPassword") instanceof String) {
            user.setUserPassword(jsonObject.getString("userPassword"));
        }
        if (jsonObject.getValue("userNickName") instanceof String) {
            user.setUserNickName(jsonObject.getString("userNickName"));
        }
    }

    public static void toJason(User user, JsonObject json) {
        if (user.getUserID() != null) {
            json.put("userID", user.getUserID());
        }
        if (user.getUserName() !=null) {
            json.put("userName", user.getUserName());
        }
        if (user.getUserPassword() !=null) {
            json.put("userPassword", user.getUserPassword());
        }
        if (user.getUserNickName() != null) {
            json.put("userNickName", user.getUserNickName());
        }
    }
}
